<template>
	<view>
		<view class="inviteList">
		  <!-- <mt-loadmore ref="loadmore" :bottom-method="loadBottom" :bottom-all-loaded="allLoaded" -->
		               <!-- :auto-fill="false"> -->
		    <view class="item" v-for="(item,index) in messageList" :class="item.isRead==0?'not_read':'read'"
		         @click="toDetail(item.id,item.mtype,item.contentId)">
		      <view>{{item.content}}</view>
		      <br>
		      {{item.createAt|toTime}}
		      <view v-show="!item.isRead" class="point"></view>
		    </view>
		    <view class="no_data" v-if="messageList.length==0">
		      <image src="../../../static/icon/default/no_data.jpg">
		    </view>
		  <!-- </mt-loadmore> -->
		</view>
	</view>
</template>


<script>
	import Message from "./Message.js";
	import {GET_MESSAGE} from "@/store/mutation-types.js";
	export default {
		created(){
			// let type = uni.getQueryVariableFromUrl("type");
			
			this.init();
		},
		filters: {
		    toTime(date) {
				// console.log(val);
				// console.log(this.toDateString());
		        // return this.toDateString(val);
				let aStrings = date.toString().split(" ");
				console.log(aStrings);
				if (aStrings[1] == "Jan") {
				    aStrings[1] = "01";
				}if (aStrings[1] == "Feb") {
				    aStrings[1] = "02";
				}if (aStrings[1] == "Mar") {
				    aStrings[1] = "03";
				}if (aStrings[1] == "Apr") {
				    aStrings[1] = "04";
				}if (aStrings[1] == "May") {
				    aStrings[1] = "05";
				}if (aStrings[1] == "Jun") {
				    aStrings[1] = "06";
				}if (aStrings[1] == "Jul") {
				    aStrings[1] = "07";
				}if (aStrings[1] == "Aug") {
				    aStrings[1] = "08";
				}if (aStrings[1] == "Sep") {
				    aStrings[1] = "09";
				}if (aStrings[1] == "Oct") {
				    aStrings[1] = "10";
				}if (aStrings[1] == "Nov") {
				    aStrings[1] = "11";
				}if (aStrings[1] == "Dec") {
				    aStrings[1] = "12";
				}
				return aStrings[5] + "-" + aStrings[1] + "-" + aStrings[2] + " " + aStrings[3];
		    }
			
		},
		onLoad(obj){
			// console.log(obj);
			this.type = obj.type;
			if (this.type == 1) {
				uni.setNavigationBarTitle({
					title:"博客提醒"
				})
			} else if (this.type == 2) {
			    uni.setNavigationBarTitle({
			    	title:"许愿提醒"
			    })
			} 
		},
		data()
		{
			return {
				messageList: [],
				type: 0,
				page: 1,
				allLoaded: false,
				wallet: {}
			}
		},
		methods: {
			// toTime(val) {
			//     return toDateString(val);
			// },
			init() {
			    let app = this;
			    let success = function (result) {
			        if (result.error == "0") {
			            for (let i = 0; i < result.data.list.length; i++) {
			                let item = result.data.list[i];
			                app.messageList.push(item);
			            }
			            if (result.data.list.length == result.data.pageSize) {
			                app.page++;
			            } else {
			                app.allLoaded = true;
			            }
			        } else {
			            app.$toast(result.error);
			        }
			    };
				const data={
					"type":app.type,
					"page":app.page
				};
				// console.log(data);
				// console.log(GET_MESSAGE);
				this.$store.dispatch(`user/${GET_MESSAGE}`,{
					data,
					onSuccess:success
				})
			    // AjaxHelper.get(CommonUtils.domainNamePrefix + "/message/selectByType?type=" + app.type+"&pageNum="+app.page, null, success);
			},
			toDetail(id, type, contentId) {
			    // Message.readMessage(id);
			    // if (type == 0) {
			    //     window.location.href = './fans.html'
			    // } else if (type == 1) {
			    //     window.location.href = './my_blog/my_blog_detail.html?symbol=message&blogId=' + contentId;
			    // } else if (type == 2) {
			    //     window.location.href = './my_wish/my_wish_detail.html?symbol=message&wishId=' + contentId;
			    // } else if (type == 3) {
			    //     window.location.href = './my_time/capsule_detail.html?symbol=message&id=' + contentId;
			    // } else if (type == 4) {
			    //     window.location.href = './invite.html'
			    // }
			}
			
			
		}
	}
</script>

<style>
page{
	background-color: #F1F1F1;
	padding: 5.33rpx;
}
.inviteList{
	background: #F1F1F1;
}
.inviteList .item{
    font-size: 32rpx;
    background: #fff;
    padding: 10.66rpx;
    margin-bottom: 5.33rpx;
    line-height: 50rpx;
}
.inviteList .read {
    font-size: 32rpx;
}
.inviteList .not_read {
    color: #ef4f4f;
    font-size: 32rpx;
}
.inviteList .point{
	position:relative;
	top: -50rpx;
    height: 21.33rpx;
    width: 21.33rpx;
    border-radius: 50%;
    background: #df4f4f;
    float: right;
    margin-right: 10px;
}
.no_data{
    text-align: center;
}
.no_data image{
    margin: 160rpx auto;
    width: 50%;
    margin-left: 53.33rpx;
}
</style>
